//
//  SpeacailSaleTableViewCell.m
//  BeautyClother
//
//  Created by dllo on 15/8/27.
//  Copyright (c) 2015年 宋爽. All rights reserved.
//

#import "SpeacailSaleTableViewCell.h"

@interface SpeacailSaleTableViewCell ()

@property (nonatomic, assign) CGFloat offWidth;
@property (nonatomic, assign) CGFloat offHeight;
@property (nonatomic, assign) int time;

@end

@implementation SpeacailSaleTableViewCell


- (void)dealloc
{
    [_image release];
    [_title release];
    [super dealloc];
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.image = [[UIImageView alloc]init];
        [self.contentView addSubview:self.image];
        [_image release];
        
        self.state = [[UILabel alloc]init];
        [self.image addSubview:self.state];
        [_state release];
        
        self.title = [[UILabel alloc]init];
        [self.contentView addSubview:_title];
        [_title release];
        
        self.date = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.contentView addSubview:self.date];
        
        
            self.time = [[[self.dic objectForKey:@"component"]objectForKey:@"expires"] intValue];
            [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES];
            NSString *day = [NSString stringWithFormat:@"%d", _time / 3600 / 24];
            NSString *hour = [NSString stringWithFormat:@"%d", _time / 3600 / 60];
            NSString *second = [NSString stringWithFormat:@"%d", _time / 3600];
            [self.date setTitle:[[[[[day stringByAppendingString:@"天"]stringByAppendingString:hour]stringByAppendingString:@"时"]stringByAppendingString:second]stringByAppendingString:@"秒"] forState:UIControlStateNormal];
        
        self.people = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.contentView addSubview:self.people];
        self.offWidth = [[UIScreen mainScreen]bounds].size.width / 375;
        self.offHeight = [[UIScreen mainScreen]bounds].size.height / 667;
        
    }
    return self;
}

- (void)timerFireMethod:(NSInteger)index
{
    self.time = self.time - 1;
    
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    self.image.frame = CGRectMake(5 *_offWidth, 0, self.frame.size.width - 10*_offWidth, self.frame.size.height - 50*_offHeight);
    self.image.layer.cornerRadius = 5;
    self.image.layer.masksToBounds = YES;
    self.state.frame = CGRectMake(20*_offWidth, 0, 80*_offWidth, 30*_offHeight);
    self.state.textAlignment = 1;
    self.title.frame = CGRectMake(10, _image.frame.size.height + 15*_offHeight, self.frame.size.width / 2, 30*_offHeight);
    self.date.frame = CGRectMake(self.frame.size.width / 2 , _image.frame.size.height + 20*_offHeight, 160*_offWidth, 20*_offHeight);
    self.people.frame = CGRectMake(self.frame.size.width / 2 + 120*_offWidth, _image.frame.size.height + 20*_offHeight, 60*_offWidth, 20*_offHeight);
    self.date.titleLabel.font = [UIFont systemFontOfSize:12];
    [self.date setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [self.date setImage:[UIImage imageNamed:@"date.png"] forState:UIControlStateNormal];
    [self.date setTintColor:[UIColor darkGrayColor]];
    
    self.people.titleLabel.font = [UIFont systemFontOfSize:12];
    [self.people setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [self.people setImage:[UIImage imageNamed:@"v.png"] forState:UIControlStateNormal];
    [self.people setTintColor:[UIColor darkGrayColor]];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
